"""
============================================
 Geometry Calculator (Functions + Parameters)

 TODO:
   - Complete the functions below
   - Use parameters and return values correctly
   - Do NOT change function names
============================================
"""

PI = 3.14

# ---------- GEOMETRY FUNCTIONS ----------

def circle_area(r):
    """
    TODO:
    - Calculate the area of a circle
    - Formula: PI * r * r
    - Store result in a variable named 'area'
    - Return 'area'
    """
    area = PI*r*r
    return area



def circle_perimeter(r):
    """
    TODO:
    - Calculate the perimeter (circumference) of a circle
    - Formula: 2 * PI * r
    - Store result in a variable named 'perimeter'
    - Return 'perimeter'
    """
    perimeter = 2* PI * r
    return perimeter



def rectangle_area(w, h):
    """
    TODO:
    - Calculate the area of a rectangle
    - Formula: w * h
    - Store result in a variable named 'area'
    - Return 'area'
    """
    area = w*h
    return area



def rectangle_perimeter(w, h):
    """
    TODO:
    - Calculate the perimeter of a rectangle
    - Formula: 2 * (w + h)
    - Store result in a variable named 'perimeter'
    - Return 'perimeter'
    """
    perimeter = 2*(w + h)
    return perimeter



def triangle_area(base, height):
    """
    TODO:
    - Calculate the area of a triangle
    - Formula: (base * height) / 2
    - Store result in a variable named 'area'
    - Return 'area'
    """
    area = (base * height)/2
    return area



# ---------- HELPER FUNCTIONS (INPUT / OUTPUT) ----------

def get_number(msg):
    """
    TODO:
    - Ask the user for a number using input(msg)
    - Convert the text to float
    - Return the float value
    """
    text = input(msg)
    value = float(text)
    return value



def show_result(label, value):
    """
    TODO:
    - Print a result in the format:
<label> = <value>
      Example:
        Area = 25.0
    """
    print( label," = ",value )
    return


# ---------- MAIN MENU FUNCTION ----------

def main():
    print("=== Geometry Lab ===")
    print("1) Circle Calculations")
    print("2) Rectangle Calculations")
    print("3) Triangle Area")
    print("4) Exit")

    choice = input("Choose (1-4): ")

    if choice == "1":
        # TODO:
        #   - Ask radius from user using get_number()
        #   - Call circle_area(r) and circle_perimeter(r)
        #   - Show both results using show_result()
        #
        # Example variable names:
        r = get_number("Enter radius:")
        a = circle_area(r)
        p = circle_perimeter(r)
        print("---Circle Results---")
        show_result("Area", a)
        show_result("Perimeter", p)
        return

    elif choice == "2":
        # TODO:
        #   - Ask width and height from user using get_number()
        #   - Call rectangle_area(w, h) and rectangle_perimeter(w, h)
        #   - Show both results using show_result()
        w = get_number("Enter widht: ")
        h = get_number("Enter height:")
        a = rectangle_area(w,h)
        p = rectangle_perimeter(w,h)
        print("---Rectangle Results---")
        show_result("Area",a)
        show_result("Perimeter",p)
        return

    elif choice == "3":
        # TODO:
        #   - Ask base and height from user using get_number()
        #   - Call triangle_area(base, height)
        #   - Show the result using show_result()
        b = get_number("Enter base: ")
        h = get_number("Enter height:")
        a = triangle_area(b,h)
        print("---Triangle Results---")
        show_result("Area",a)
        return

    elif choice == "4":
        print("Exiting program...")
        return

    else:
        print("Invalid choice.")

    print()      # empty line for readability

# Do not remove this line.
# Your program will start from here.
main()
